# 请求封装
import requests
from utils.logger import logger
from config.config import settings


class RequestUtils:
    def __init__(self):
        self.base_url = settings.BASE_URL
        self.headers = {"Content-Type": "multipart/form-data",  # 修改请求数据类型multipart/form-data
                        "application": "web", "application_client_type": "pc"}

    def get(self, endpoint, params=None):
        url = f"{self.base_url}{endpoint}"
        logger.info(f"GET {url}")
        response = requests.get(url, headers=self.headers, params=params)
        logger.info(f"Response: {response.status_code} {response.text}")
        return response

    def post(self, endpoint, params=None, data=None, cookie=None):
        url = f"{self.base_url}{endpoint}"
        logger.info(f"POST {url}")
        response = requests.post(url, headers=self.headers, params=params, data=data, cookies=cookie)
        logger.info(f"Response: {response.status_code} {response.text}")
        return response
